{**
 * yet another version of _pager.tpl by alex yaroshevich
 * 
 * @input:	array	$list;		// items to show. usually contains all page numbers in list
 * @input:	integer	$current;	// current item, for selecting
 * @input:	integer	$ends = 1;	// links quantity at ends
 * @input:	integer $parallax = 4;	// left|right parallax for concrete item
 * @input:	string	$url_template = "/page_@p/";	// template for url-generating
 * or:
 * @input:	array	$rs;		// result set which contains basic information about pager
 * @out:	
 *}

{* if exists some RecordSet value - change this part of code to use it *}
{if !$RecordSet && $rs}{assign var=RecordSet value=$rs}{/if}
{if $RecordSet}
{assign var=list value=$RecordSet.pages}
{assign var=current value=$RecordSet.current_page}
{/if}
{**}

{if !$quantity}{assign var=quantity value=$list|@sizeof}{/if}
{if !$ends}{assign var=ends value=1}{/if}
{if !$url_template}{assign var=url_template value="/page@p/"}{/if}
{if !$parallax}{assign var=parallax value=4}{/if}

{if $quantity > 1}
{strip}
	{* lprlx: current-leftparallax > atend_quantity+1, because first&second links will be printed *}
	{assign var=lprlx value=$current-$parallax-1|@max:1}
	{if $lprlx <= $ends+1}{assign var=lprlx value=0}{/if}
	
	{* rprlx: rightparallax < list_quantity-atends_quantity-1, because last&prelast links also will be printed *}
	{assign var=rprlx value=$current+$parallax+1|@min:$quantity}
	{if $rprlx >= $quantity-$ends}{assign var=rprlx value=$quantity}{/if}
	
	{*<div class="debug">quantity:{$quantity}, l:{$lprlx}, r:{$rprlx}</div>*}
	
	<span class="leftonly">Страницы:</span>
	{if $quantity > 2}
	<span class="leftright">
		{if $current>1}&larr;&nbsp;<a href="{$url_template|replace:'@p':$current-1}">назад</a>{else}<span class="inactive">&larr; назад</span>{/if}&nbsp;
		{if $current<$quantity}<a href="{$url_template|replace:'@p':$current+1}">вперед</a>&nbsp;&rarr;{else}<span class="inactive">вперед &rarr;</span>{/if}
	</span>
	{/if}
	
	<div class="listing">
	{assign var=leftdots value=0}{assign var=rightdots value=0}
	{foreach from=$list item=n name=list}
	{if $n != $current}
	{if ( $lprlx < $n and $n < $current)
	 or ( $current < $n and $n < $rprlx)
	 or ( $n <= $ends ) or ( $quantity-$ends < $n )}
		<span class="prlx{$current-$n|abs}"><a href="{$url_template|replace:'@p':$n}">{$n}</a></span>
	{elseif ( !$leftdots and $n < $current)}{assign var=leftdots value=1}<a href="{assign var=n value=$lprlx/2+1|@intval}{$url_template|replace:'@p':$n}">...</a>{elseif ( !$rightdots and $current < $n)}{assign var=rightdots value=1}<a href="{assign var=n value=$rprlx/2+$quantity/2|@intval}{$url_template|replace:'@p':$n}">...</a>{/if}
	{else}<span class="selected">{$n}</span>{/if}
	{/foreach}
	</div>
	<div class="pusher"></div>
{/strip}
{/if}
